<?php

class Logout_Controller extends Base_Controller {
  
  public $restful = true;
  public $layout = 'layouts.default';


  public function get_index(){
  session_start();
  $token = '';
  $params = '';
  $fb_param = array('state', 'access_token', 'code');  
  $i = 0;

  foreach($_SESSION as $key => $value)
  {
    $params[$fb_param[$i]] = $key;
    $i++;
  }

  if(isset($params['access_token']))
  {
    $token_param = $params['access_token'];
    $token = $_SESSION[$token_param];
  }
 
  if($token)
  {
    $graph_url = "https://graph.facebook.com/me/permissions?method=delete&access_token=" . $token;
    $ch = curl_init();

    curl_setopt($ch, CURLOPT_URL, $graph_url);
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

    $result = json_decode(curl_exec($ch));
    curl_close($ch);
 
    if($result)
    {
      session_destroy();
    }
  } 

  
    return Redirect::home();
  }
  
}

?>
